# rpm -q postfix || yum -y install postfix
# yum -y install mailx
# systemctl start postfix
# netstat -utnlp | grep :25
from email.header import Header
from email.mime.text import MIMEText
import smtplib
# message: 消息
msg = MIMEText("python test", "plain", "utf8")  # 定义邮件的内容  plain:纯文本
# 设置头部信息
msg["From"] = Header("发送者", "utf8")
msg["To"] = Header("接收者", "utf8")
msg["Subject"] = Header("py test", "utf8")  # 设置标题
smtp = smtplib.SMTP("127.0.0.1")  # 创建SMTP类的对象, 用于发送邮件
# 发送邮件  root(发送者) -> [zhangsan, lisi] (接收者们)
# useradd zhangsan   useradd lisi    创建两个用户，用于邮件的接收
sender = "root"  # 真正的邮件发送者
receivers = ["zhangsan", "lisi"]  # 真正的邮件接受者
# msg 转换成字节串发送 msg.as_bytes()
smtp.sendmail(sender, receivers, msg.as_bytes())

# 代码执行前
# [root@localhost pypkgs]# mail -u zhangsan
# No mail for zhangsan
# [root@localhost pypkgs]# mail -u lisi
# No mail for lisi
# 代码执行后
# [root@localhost pypkgs]# mail -u zhangsan
# Heirloom Mail version 12.5 7/5/10.  Type ? for help.
# "/var/mail/zhangsan": 1 message 1 new
# >N  1 =?utf8?b?5Y+R6YCB6IC  Wed Jan 26 22:38  19/682   "py test"
